package com.itheima.aop;

import com.itheima.mapper.OperateLogMapper;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * ClassName:CalcTime
 * Package:com.itheima.aop
 * Description:
 *
 * @Author 老大
 * @Create 2024/5/9 10:10
 * @Version 1.0
 */
@Component
@Slf4j
@Aspect
public class CalcTime {


    @Around("execution(* com.itheima.service.impl.*.*(..))")
    public  Object calcTime(ProceedingJoinPoint joinPoint) throws Throwable {
        String name = joinPoint.getTarget().getClass().getName();   //获取类名
        String methodName = joinPoint.getSignature().getName();     //获取方法名
        Object[] args = joinPoint.getArgs();                        //获取方法名参数

        log.info("类名:{} , 方法名:{} ,参数:{} " , name , methodName , args);
        long start = System.currentTimeMillis();

        Object result = joinPoint.proceed();

        long end = System.currentTimeMillis();
        System.out.println("耗时:" + (end - start) + "毫秒");


        return result;
    }
}
